import comTitle from "@/views/com/com_title.vue";
import { putObj } from '@/api/shop/info.js'
export default {
    components: {
        comTitle,
    },
    data() {
        return {
            labelWidth: "120px",
            disabled: false,
            ruleForm: {
            },
            rules: {
                shopName: [{ required: true, message: '请输入门店名称', trigger: 'blur' }],
                gysdz: [{ required: true, message: '请选择门店区域', trigger: 'change' }],
                shopType: [{ required: true, message: '请选择门店归属', trigger: 'change' }],
                businessType: [{ required: true, message: '请选择所属业务', trigger: 'change' }],
                longitude: [{ required: true, message: '请输入经度', trigger: 'blur' }],
                latitude: [{ required: true, message: '请输入纬度', trigger: 'blur' }],
            },
            mdguishuList: [ //门店归属
                {
                    value: '01',
                    label: "平台",
                },
                {
                    value: '02',
                    label: "分公司",
                },
                {
                    value: '03',
                    label: "代理商",
                }
            ],
            yewuList: [  //业务
                {
                    label: "商超",
                    value: '02'
                },
                {
                    label: "咖吧",
                    value: '05'
                },
                {
                    label: "洗衣",
                    value: '03'
                },
                {
                    label: "家政",
                    value: '04'
                }
            ]
        }
    },
    watch: {
        '$route'() {
            let obj = { ...this.$route.query }
            this.ruleForm = obj
            if (obj.businessType) {
                obj.businessType = obj.businessType.split(',')
            }
        }
    },
    mounted() {
        let obj = { ...this.$route.query }
        this.ruleForm = obj
        if (obj.businessType) {
            obj.businessType = obj.businessType.split(',')
        }
    },
    methods: {
        save() {   //保存
            console.log(this.ruleForm)
            /* if (this.ruleForm.sptm == 0) {
                this.rules.sptm1[0].required = false; //商品条码
            } else {
                this.rules.sptm1[0].required = true;
            } */
            let obj = { ...this.ruleForm }
            obj.businessType = obj.businessType.join(',')
            this.$refs['ruleForm'].validate((valid) => {
                if (valid) {
                    putObj(obj).then(val => {
                        this.$message.success('编辑成功')
                        this.quxiao('ruleForm')
                    })
                } else {
                    this.$message.error('编辑失败')
                    return false;
                }
            });
        },
        quxiao(ruleForm) {  //取消
            this.$router.go(-1)
            this.$refs[ruleForm].resetFields();
            this.ruleForm = {

            }
        },
    },

} 